var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0}), (o.TableRule = void 0);
var n = t("ConfS"),
    r = t("Const"),
    a = t("Platforms"),
    i = 0,
    s = (function () {
        function t() {
            (this.showRuless = {}), (this.hideRules = {}), (this.showingRuless = {}), (this.pauseRuless = {});
        }
        return (
            (t.prototype.init = function (t, e, o, r, i, s) {
                for (var c in ((this.name = t), (this.multi = e), (this._show = r), (this._hide = s), this.showRuless))
                    (this.showRuless[c].length = 0), delete this.showRuless[c];
                for (var c in this.hideRules) delete this.hideRules[c];
                for (var l = 0, u = this.getRules(o); l < u.length; l++) {
                    var p = u[l],
                        f = this.showRuless[p.规则];
                    switch ((f || (this.showRuless[p.规则] = f = new Array()), t)) {
                        case "横幅":
                        case "推荐组件横幅":
                        case "横幅原生模版广告":
                            var d = !1;
                            if (
                                ((0 == p.dx && 1 == p.dy && 0 == p.offsetX && 0 == p.offsetY) ||
                                    (p.不显示的平台 &&
                                    p.不显示的平台.indexOf("抖音小游戏") > -1 &&
                                    p.不显示的平台.indexOf("VIVO小游戏") > -1
                                        ? (d = !0)
                                        : console.error(
                                              t +
                                                  " " +
                                                  p.名称 +
                                                  " 不显示的平台不正确：" +
                                                  p.不显示的平台 +
                                                  "\n非底部居中的不能在抖音小游戏或VIVO小游戏里展示：" +
                                                  p.不显示的平台
                                          )),
                                p.显示的平台 && console.error(t + " " + p.名称 + " 不需要显示的平台：" + p.显示的平台),
                                p.名称 == a.default.loadingName || "start_" == p.名称)
                            ) {
                                if (
                                    ("OPPO小游戏,VIVO小游戏,华为快游戏" != p.不显示的平台 &&
                                        console.error(t + " " + p.名称 + " 不显示的平台不正确：" + p.不显示的平台),
                                    n.DatasManager.a)
                                )
                                    continue;
                            } else
                                p.名称 == a.default.gameName
                                    ? (p.不显示的平台 && p.不显示的平台.indexOf("抖音小游戏") > -1) ||
                                      console.error(
                                          t +
                                              " " +
                                              p.名称 +
                                              " 不显示的平台（" +
                                              p.不显示的平台 +
                                              "）必须包含“抖音小游戏”"
                                      )
                                    : p.不显示的平台 &&
                                      (d || console.error(t + " " + p.名称 + " 不需要不显示的平台：" + p.不显示的平台));
                            n.DatasManager.a &&
                                (0 == p.名称.indexOf("扩展") &&
                                    ((p.规则 = p.规则.replace("显示扩展", "显示")), (p.名称 = p.名称.substr(2))),
                                p.显示时间 > 0 && ((p.显示时间 = 0), (p.隐藏时间 = 0))),
                                a.default.类原生和原生() &&
                                    p.显示时间 > 0 &&
                                    ((p.显示时间 = 0),
                                    (p.隐藏时间 = 0),
                                    console.log(a.default.platformType + "，" + p.规则 + " 显示时间改为0")),
                                f.length && console.error("同一规则不能多于一条：" + p.规则);
                    }
                    f.push(p);
                }
                if (i)
                    for (var h = 0, y = this.getRules(i); h < y.length; h++) {
                        p = y[h];
                        this.hideRules[p.规则] = !0;
                    }
            }),
            (t.prototype.pause = function () {
                for (var t in this.showingRuless)
                    for (
                        var e = (this.pauseRuless[t] = new Array()), o = 0, n = this.showingRuless[t];
                        o < n.length;
                        o++
                    ) {
                        var r = n[o],
                            a = r.target;
                        r.target = null;
                        var i = JSON.parse(JSON.stringify(r));
                        (i.target = a), e.push(i);
                    }
                this.hideAll();
            }),
            (t.prototype.resume = function () {
                for (var t in this.pauseRuless) {
                    for (var e = this.pauseRuless[t], o = 0, n = e; o < n.length; o++) {
                        var r = n[o];
                        this._run(r);
                    }
                    (e.length = 0), delete this.pauseRuless[t];
                }
            }),
            (t.prototype.show = function (t) {
                (t.引导不出 && !r.default.guideAllComplete()) || this._show(t);
            }),
            (t.prototype.hide = function (t) {
                (t.target = null), this._hide(t);
            }),
            (t.prototype.hideAll = function () {
                for (var t in (a.default.delays.clear("TableRule" + this.name), this.showingRuless)) this.hideOne(t);
            }),
            (t.prototype.hideOne = function (t) {
                for (var e = this.showingRuless[t], o = 0, n = e; o < n.length; o++) {
                    var r = n[o];
                    this.hide(r);
                }
                (e.length = 0), delete this.showingRuless[t];
            }),
            (t.prototype._run = function (t) {
                var e = this;
                if (this._hide) {
                    if (this.multi) (t.ruleIndex = ++i), this.show(t);
                    else if (t.显示时间 > 0) {
                        var o = function () {
                            e.show(t),
                                a.default.delays.delay({
                                    time: t.显示时间,
                                    action: function () {
                                        e.hide(t),
                                            t.隐藏时间 > 0 &&
                                                a.default.delays.delay({
                                                    time: t.隐藏时间,
                                                    action: o,
                                                    group: "TableRule" + e.name
                                                });
                                    },
                                    group: "TableRule" + e.name
                                });
                        };
                        a.default.delays.delay({time: 0.5, action: o, group: "TableRule" + this.name});
                    } else this.show(t);
                    var n = this.showingRuless[t.名称];
                    n ? n.push(t) : (this.showingRuless[t.名称] = [t]);
                } else this.show(t);
            }),
            (t.prototype.run = function (t, e, o) {
                "隐藏" == e &&
                    this.showingRuless[o] &&
                    (a.default.delays.clear("TableRule" + this.name), this.hideOne(o)),
                    this.hideRules[e + o] && this.hideAll();
                var n = this.showRuless[e + o];
                if (n) {
                    if ((this.multi || this.hideAll(), this.执行间隔时间 > 0)) {
                        var r = new Date().getTime(),
                            i = r - this.上次执行时间;
                        if (i < this.执行间隔时间)
                            return void console.error("距离上次执行" + i + "毫秒 <" + this.执行间隔时间 + "毫秒");
                        this.上次执行时间 = r;
                    }
                    for (var s = 0, c = n; s < c.length; s++) {
                        var l = c[s];
                        (l.频率 && (++l.频率索引 >= l.频率.length && (l.频率索引 = 0), !l.频率[l.频率索引])) ||
                            ((l.target = t), this._run(l));
                    }
                }
            }),
            (t.prototype.getRules = function (t) {
                var e = new Array();
                if (t) {
                    var o = t
                        .replace(/\/\/.*/g, "")
                        .replace(/^\s*|\s*$/g, "")
                        .split(/\s*\n\s*/);
                    if (o.length && o[0]) {
                        var r = c(o[0]);
                        if (r.动作 && r.名称)
                            (r.审核不出 && n.DatasManager.a) || (l(r) && u(r) && e.push(r)), (r = null);
                        else {
                            if (r.审核不出 && n.DatasManager.a) return e;
                            if (!l(r) || !u(r)) return e;
                            (this.执行间隔时间 = r["执行间隔时间"]),
                                this.执行间隔时间 > 0 && ((this.执行间隔时间 *= 1e3), (this.上次执行时间 = 0));
                        }
                        o.shift();
                        for (var a = 0, i = o; a < i.length; a++) {
                            var s = i[a];
                            (h = c(s)).动作 && h.名称
                                ? (h.审核不出 && n.DatasManager.a) || (l(h) && u(h) && e.push(h))
                                : console.error("规则格式不正确：" + s);
                        }
                        if (r)
                            for (var p in r)
                                for (var f = 0, d = e; f < d.length; f++) {
                                    var h;
                                    p in (h = d[f]) || (h[p] = r[p]);
                                }
                    }
                }
                return e;
            }),
            t
        );
    })();
function c(t) {
    for (var e = {}, o = 0, n = t.match(/\S+\s*[:\uff1a]\s*\S+|\S+/g); o < n.length; o++) {
        var r = n[o].split(/\s*[:\uff1a]\s*/);
        if (2 == r.length)
            switch (r[0]) {
                case "频率":
                    e[r[0]] = r[1];
                    break;
                default:
                    /^[+-\d]+$/.test(r[1]) ? (e[r[0]] = parseInt(r[1])) : (e[r[0]] = r[1]);
            }
        else
            switch (r[0]) {
                case "左":
                case "中":
                case "右":
                case "上":
                case "中2":
                case "下":
                    e[r[0]] = 0;
                    break;
                default:
                    e[r[0]] = 1;
            }
    }
    var a,
        i = {ruleIndex: 0, dx: 0, dy: 1, offsetX: 0, offsetY: 0};
    for (var s in (e.规则 &&
        (a = e.规则.match(/^(\u663e\u793a|\u9690\u85cf)(.+)$/)) &&
        ((i.动作 = a[1]), (i.名称 = a[2])),
    e))
        switch (s) {
            case "左":
                (i.dx = -1), (i.offsetX = e.左);
                break;
            case "中":
                (i.dx = 0), (i.offsetX = e.中);
                break;
            case "右":
                (i.dx = 1), (i.offsetX = -e.右);
                break;
            case "上":
                (i.dy = -1), (i.offsetY = e.上);
                break;
            case "中2":
                (i.dy = 0), (i.offsetY = e.中2);
                break;
            case "下":
                (i.dy = 1), (i.offsetY = -e.下);
                break;
            case "推荐1":
            case "推荐2":
            case "除推荐1":
            case "全部":
                i.CPBIndices = s;
                break;
            case "频率":
                i.频率 = new Array();
                for (var c = 0, l = e.频率.match(/0|1/g); c < l.length; c++) {
                    var u = l[c];
                    i.频率.push("1" == u ? 1 : 0);
                }
                i.频率索引 = -1;
                break;
            default:
                i[s] = e[s];
        }
    return i;
}
function l(t) {
    return t.显示的平台
        ? t.显示的平台.indexOf(a.default.platformType) > -1
        : !t.不显示的平台 || -1 == t.不显示的平台.indexOf(a.default.platformType);
}
function u(t) {
    return t.肥屏
        ? a.default.platformCtrl.肥屏
        : t.长屏
        ? r.default.wid0 > r.default.hei0
            ? r.default.stageWid >= 1280
            : r.default.stageHei >= 1280
        : !t.短屏 || (r.default.wid0 > r.default.hei0 ? r.default.stageWid <= 1280 : r.default.stageHei <= 1280);
}
o.TableRule = s;
